var SwordToolTips = new Class({
    Implements:[Events,Options],
    style:{
        styBase:'box_sty' ,
        defSty:'c',
        validatorSty:'v',
        defCont:'cont'
    },
    options:{
    	speed:2000
    },
    tips:new Hash(),
    initialize:function(options) {
        this.setOptions(options);
    },
    createTip:function(tip) {
        if (!$defined(tip['className'])) {
        	if(tip.type=="validator"){
        		tip['className'] = this.style.validatorSty;
        	}else{
        		tip['className'] = this.style.defSty;
        	}
        }
        var tipDiv = new Element('div', {
            'name'    : tip['divId'],
            'class' : this.style.styBase + "_" + tip['className'],
            'clsName':this.style.styBase + "_" + tip['className'],
            'styles': {
            	'display':'none',
                'position':'absolute',
                'z-index':tip['z-index']||0,
                'left': -500,
                'top': -500
            }
        });
        tipDiv.innerHTML = ("<div class='t'><div class='l'></div><div class='r'></div></div>" +
                            "<div class='c'><div class='cont' id='cont'></div></div>" +
                            "<div class='b'><div class='l'></div><div class='r'></div></div>");
        if ($defined(tip['width'])) {
            tipDiv.setStyle("width", tip['width']);
        }
        var msgDiv = tipDiv.getElements("div[id='cont']")[0];
        msgDiv.appendText(tip.message);
        tipDiv.inject(document.body);
        this.tips.set(tip['divId'], tipDiv);
    },
    get:function(key) {
        return this.tips.get(key);
    },
    getCont:function(key) {
        var tip = this.get(key);
        return tip.getElements("div[id='cont']")[0];
    },
    show:function(key, el, options,w) {
    	var c = $$("div[class='box_sty_c']");
    	var v = $$("div[class='box_sty_v']");
    	c.each(function(it){
			it.setStyle("display","none");
    		c.setStyle("display","none");
		});
        if (!$defined(options)) options = {};
        var flag = options.flag;
        var autoHidden = (options.autoHidden == null) ? false : options.autoHidden;
        var position = options.position;
        var tip = this.get(key);
      //  tip.fade('in');
        tip.setStyle("display","");
//        tip.setStyle.delay(1,tip,["display",""]);
        var msgDiv = this.getCont(key);
        if ($defined(flag)) {
            msgDiv.set('class', flag);
        } else {
            msgDiv.set('class', this.style.defCont);
        }
        if ($defined(options.className)) {
            msgDiv.addClass(options.className);
            msgDiv['state'] = options.className;
        } else {
            msgDiv.addClass(msgDiv['state']);
        }
        msgDiv.el = el;
        msgDiv.flag = flag;
        switch (flag) {
            case 'top':
                //tip.setStyles({'left':el._getPosition().x,'top':el._getPosition().y - tip.offsetHeight});
                xyposition(el,tip,'top');
                break;
            case 'bottom':
                tip.setStyles({'left':el._getPosition().x,'top':el._getPosition().y + tip.offsetHeight});
                break;
            case 'left':
                tip.setStyles({'left':el._getPosition().x - el.offsetWidth,'top':el._getPosition().y});
                break;
            case 'right':
                tip.setStyles({'left':el._getPosition().x + el.offsetWidth,'top':el._getPosition().y});
                break;
            case 'define':
                tip.setStyles({'left':position.x + el.offsetWidth,'top':position.y});
                break;
            default:
                //tip.setStyles({'left':el._getPosition().x,'top':el._getPosition().y - tip.offsetHeight});
                xyposition(el,tip,'top');
                break;
        }
        if (autoHidden != false) {
            this.hide.delay(2000, this, key);
        }
    },
    hide:function(key) {
        var tip = this.get(key);
        // if(tip)tip.fade('out');去掉动画效果直接隐藏
        if(tip)tip.setStyle("display","none");
    },
    dispose:function(key) {
        this.get(key).destroy();
    },
    fillText:function(key, message) {
        this.getCont(key).empty().appendText(message);
    }
});



